package com.example.mobile2021606129ly0427;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;



public class MainActivity extends AppCompatActivity {
    private RecyclerView mrecyclerview;
    private HomeAdapter mAdapter;
    private String[] title={"国际大厦停车场","国际大厦停车场","国际大厦停车场","国际大厦停车场","国际大厦停车场"};
    private String[] seat={"空位：30","空位：30","空位：30","空位：30","空位：30"};
    private String[] price={"价格：5元/小时","价格：5元/小时","价格：5元/小时","价格：5元/小时","价格：5元/小时"};
    private String[] distance={"距离：20公里","距离：20公里","距离：20公里","距离：20公里","距离：20公里"};
    private String[] address={"地址：佛山市高明区富湾镇学府路8号","地址：佛山市高明区富湾镇学府路8号","地址：佛山市高明区富湾镇学府路8号","地址：佛山市高明区富湾镇学府路8号","地址：佛山市高明区富湾镇学府路8号"};
    private String[] information={"更多信息","更多信息","更多信息","更多信息","更多信息"};
    private int[] imag={R.drawable.pl,R.drawable.pl,R.drawable.pl,R.drawable.pl,R.drawable.pl};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mrecyclerview = (RecyclerView) findViewById(R.id.recyclerView);
        mrecyclerview.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new HomeAdapter();
        mrecyclerview.setAdapter(mAdapter);
    }

       class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
           @Override
           public HomeAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
               ViewHolder holder=new ViewHolder(LayoutInflater.from(MainActivity.this).inflate(R.layout.recycler,parent,false));
               return holder;
           }


           @Override
           public void onBindViewHolder(@NonNull HomeAdapter.ViewHolder holder, int position) {
               holder.img.setImageResource(imag[position]);
               holder.rv_title.setText(title[position]);
               holder.rv_sea.setText(seat[position]);
               holder.rv_add.setText(address[position]);
               holder.rv_dis.setText(distance[position]);
               holder.rv_in.setText(information[position]);
               holder.rv_pri.setText(price[position]);

           }

           @Override
           public int getItemCount() {
               return title.length;
           }

        class ViewHolder extends RecyclerView.ViewHolder{
            TextView rv_title,rv_sea,rv_pri,rv_dis,rv_add,rv_in;
            ImageView img;
            public ViewHolder(View view){
                super(view);
                rv_title=(TextView)view.findViewById(R.id.rv_title);
                rv_sea=(TextView)view.findViewById(R.id.rv_sea);
                rv_pri=(TextView)view.findViewById(R.id.rv_pri);
                rv_dis=(TextView)view.findViewById(R.id.rv_dis);
                rv_add=(TextView)view.findViewById(R.id.rv_add);
                rv_in=(TextView)view.findViewById(R.id.rv_in);
                img=(ImageView)view.findViewById(R.id.img);

            }

        }
    }
    }
